/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.useroption;

import android.text.TextUtils;

import com.alstudio.module.xmpp.protocol.xmpp.packact.ALXmppDomainConfig;
import com.alstudio.module.xmpp.protocol.xmpp.packact.IQNameSpace;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.AlXmlTag;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate;
import com.alstudio.utils.formater.BooleanUtils;
import com.alstudio.utils.notification.SystemSettings;

/**
 * 提交用户选项
 * 
 * @author alonso lee
 * 
 */
public class CommitUserOptionsIQCreator extends BaseIQTemplate {

	private SystemSettings settings;

	/**
	 * 
	 */
	public CommitUserOptionsIQCreator(String domain, SystemSettings settings) {
		// TODO Auto-generated constructor stub
		this.domain = domain;
		this.settings = settings;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate
	 * #getIQXml()
	 */
	@Override
	public String getIQXml() {
		// TODO Auto-generated method stub
		mALIQCreator.setNs(IQNameSpace.NS_COMMIT_USER_OPTION);
		mALIQCreator.setType(IQ_TYPE_SET);
		to = ALXmppDomainConfig.getALXmppDomainConfig().getDomainByNameSpace(
				mALIQCreator.getNs());
		mALIQCreator.setTo(to + domain);

		// vcard起始节点
		AlXmlTag tag = new AlXmlTag("item");
		String key = null, value = null;
		switch (settings.getModifyType()) {
		case SETTING_MODIFY_TYPE_BLOCK_STRANGER_CALL:
			key = "blockstrangercall";
			value = BooleanUtils.parseOnOf(settings.isBlockstrangercall());
			break;
		case SETTING_MODIFY_TYPE_BLOCK_STRANGER_MESSAGE:
			key = "blockstrangermsg";
			value = BooleanUtils.parseOnOf(settings.isBlockstrangermsg());
			break;
		case SETTING_MODIFY_TYPE_CALL_NOTICE:
			key = "callnotify";
			value = BooleanUtils.parseOnOf(settings.getCallNoticeState());
			break;
		case SETTING_MODIFY_TYPE_HIDING:
			key = "hiding";
			value = BooleanUtils.parseOnOf(settings.isHiding());
			break;
		case SETTING_MODIFY_TYPE_SILENCE:
			key = "slience";
			value = BooleanUtils.parseOnOf(settings.getMuteState());
			if (settings.getMuteState()) {
				// 开启了静音模式
				value += "|" + settings.getMuteStartTime() + "|"
						+ settings.getMuteEndTime();
			}
			break;
		case SETTING_MODIFY_TYPE_SOUND:
			key = "sound";
			value = BooleanUtils.parseOnOf(settings.getSoundState());
			break;
		case SETTING_MODIFY_TYPE_VIBRATION:
			key = "vibrate";
			value = BooleanUtils.parseOnOf(settings.getVbrationState());
			break;
		default:
			return null;

		}

		tag.setAtt("key", key);
		tag.setAtt("val", value);

		tagList.add(tag);

		String xml = "";
		try {
			xml = mALIQCreator.getXml();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return xml;
	}

}
